<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <template v-if="isDeleteShow">
        <span @click="$emit('delAll', historySearch)">全部删除</span>
        &nbsp;&nbsp;
        <span @click="isDeleteShow = false">完成</span>
      </template>
      <van-icon v-else name="delete" @click="isDeleteShow = true" />
    </van-cell>
    <van-cell
      :title="item"
      v-for="(item, index) in historySearch"
      :key="index"
      @click="clickFn(item)"
    >
      <van-icon
        name="close"
        v-show="isDeleteShow"
        @click="historySearch.splice(index, 1)"
      />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: "SearchHistory",
  components: {},
  props: {
    historySearch: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      isDeleteShow: false, //控制删除显示状态
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    clickFn(val) {
      if (!this.isDeleteShow) {
        //false是非删除状态
        //非删除就调用父组件Search请求搜索结果方法
        this.$emit("input", val);
      }
    },
  },
};
</script>

<style scoped lang="less"></style>
